﻿using UnityEngine;
using System.Collections;

public class Gun : MonoBehaviour {

    public int MissileIndex;
    public GameObject[] MissilePrefabs;

    /// <summary>
    /// 发射导弹。
    /// </summary>
    public void Launch()
    {
        if (MissileIndex < 0 || MissileIndex > MissilePrefabs.Length)
            return;
        var prefab = MissilePrefabs[MissileIndex];
        var missileRoot = (GameObject)Instantiate(prefab, mTransform.position, Quaternion.identity);
        missileRoot.transform.DetachChildren();
        Destroy(missileRoot);
    }

    protected void Awake()
    {
        mTransform = transform;
    }

    private Transform mTransform;
}
